<template>
	<view class="warp">
		<!-- 顶部 start -->
		<!-- #ifdef WEB -->
		<view class="navbar_top">
			<uv-navbar leftText="返回" :fixed="false" title="必考试卷" border :safeAreaInsetTop="false" :placeholder="true" @leftClick="jumpUrl('1','navigateBack')" @rightClick="jumpUrl('/pages/index/index','redirectTo')">
				<template v-slot:left>
					<view class="uv-nav-slot">
						<uv-icon name="arrow-left" size="19"></uv-icon>
					</view>
				</template>
				<template v-slot:right>
					<view class="uv-nav-slot">
						<uv-icon name="home" size="19"></uv-icon>
					</view>
				</template>
			</uv-navbar>
		</view>
		<uv-gap height="44" bgColor="#F1F1F5"></uv-gap>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<uv-navbar leftText="返回" :fixed="true" title="必考试卷" border :safeAreaInsetTop="true" :placeholder="true" @leftClick="jumpUrl('1','navigateBack')" @rightClick="jumpUrl('/pages/index/index','redirectTo')">
			<template v-slot:left>
				<view class="uv-nav-slot">
					<uv-icon name="arrow-left" size="19"></uv-icon>
				</view>
			</template>
			<template v-slot:right>
				<view class="uv-nav-slot">
					<uv-icon name="home" size="19"></uv-icon>
				</view>
			</template>
		</uv-navbar>
		<!-- #endif -->
		<!-- 顶部 end -->
		<!-- 列表 start -->
		<view class="test_list">
			<view class="test_item" v-for="(v,k) in rows" :key="k">
				<view class="test_item_row">
					<view class="item_row_l" @click="jumpUrl('/pages/test/details?id='+v.test_id)">
						<uv-icon name="order" color="#79b1fe" size="48rpx"></uv-icon>
						<view class="test_item_title line_1">
							{{v.test_title}}
						</view>
					</view>
					<view class="createtime" v-if="v.course_id > 0" @click="jumpUrl('/pages/course/details?id='+v.course_id+'&lesson_id=0')">
						<image :src="IMG_URL+'course2.png'" mode="aspectFit"></image>
						查看课程
					</view>
				</view>
			</view>
			<uv-load-more :status="apiStatus" v-if="rows.length > 0" />
			<uv-empty v-if="rows.length == 0" text="无必考内容" mode="data"></uv-empty>
		</view>
		<!-- 列表 end -->
		<!-- 底部tabbar start -->
		<bastTabbar :tabbar_index="100"></bastTabbar>
		<!-- 底部tabbar end -->
	</view>
</template>

<script>
	import bastTabbar from '@/component/base-tabbar.vue'
	export default {
		components: {
			bastTabbar,
		},
		onReachBottom() {
			console.log('onReachBottom')
			this.page += 1
			this.user_test()
		},
		onLoad() {
			this.user_test()
		},
		data() {
			return {
				rows: [],
				IMG_URL: this.$IMG_URL,
				//
				page: 1,
				pagesize: 20,
				apiMore: true,
				apiStatus: 'loadmore',
				apiPost: false,
			}
		},
		methods: {
			async user_test() {
				if (this.apiPost || this.apiMore===false) {
					return false
				}
				const res = await this.$myRequest({
					url: "test/user_assign",
					type: "post",
					data: {page:this.page,pagesize:this.pagesize},
				});
				if (res.code) {
					this.apiMore = res.data.length < this.pagesize ? false : true
					this.apiStatus = res.data.length < this.pagesize ? "nomore" : "loadmore"
					this.rows = this.rows.length > 0 ? [...this.rows, ...res.data] : res.data
				}
			},
		}
	}
</script>

<style lang="scss">
	.warp{
		background-color: #FFF;
		min-height: 100vh;
		max-width: 1600rpx;
		margin: auto;
		.navbar_top{
			z-index: 1000;background-color: red;position: relative;
			.uv-navbar{
				position: fixed;
				width: 100%;
				max-width: 1600rpx;
			}
		}
		.test_list{
			padding: 20rpx;
			font-size: 30rpx;
			.test_item{
				padding: 20rpx 0;
				border-bottom: 1px dashed #909399;
				.test_item_row{
					display: flex;
					justify-content: space-between;
					align-items: center;
					.item_row_l{
						display: flex;
						flex: 1;
						align-items: center;
						.test_item_title{
							margin-left: 10rpx;
						}
					}
					.createtime{
						text-align: right;
						font-size: 28rpx;
						color: crimson;
						display: flex;
						align-items: center;
						image{
							margin: 0 10rpx;
							width: 40rpx;
							height: 40rpx;
						}
					}
					.dpy{
						width: 240rpx;
						text-align: right;
						font-size: 28rpx;
						color: #f39c12;
					}
				}
			}
		}
	}
</style>